diff --git a/library/cc_processor.php b/library/cc_processor.php index 6ac2382..88f23a7 100644 --- a/library/cc_processor.php +++ b/library/cc_processor.php @@ -1,1272 +1,1343 @@ * Date: 2009-11-09 * Version: 1.0 */ session_start(); // currency format setlocale(LC_MONETARY, 'en_US'); class CreditCardProcessor { // default cart items, must be set by external application after instantiating this class var $cart_items = array('service1'=>array('price' => 10, 'unit' => 'unit1', 'description' => 'First Item', 'duration' => 'N/A', 'qty' => 1 ), 'service2'=>array('price' => 20, 'unit' => 'unit2', 'description' => 'Second Item', 'duration' => 'N/A', 'qty' => 1 ) ); // html hidden elements that need to be preserved between submits by the application that uses this form // must be set by external application after instantiating this class var $hidden_elements = ''; // information about the buyer obtained during login in the application using this class // must be set by external application after instantiating this class var $user_account = ''; // set this to a css style for displaying the titles var $chapter_class = ''; // fancy odd rows var $odd_row_class = ''; // fancy even rows var $even_row_class = ''; var $notify_merchant = true; // set to send notification about the transaction to the merchant var $notify_buyer = true; // set to send notification about the transaction to the buyer var $transaction_data = false; // set after transaction has been sucesfull var $billing_name = ''; // saved after transaction is sucessfull var $billing_address = ''; // saved after transaction is sucessfull var $note = ''; // can be set to add a note to the transaction var $environment = 'live'; // set it to 'live' for live transactionr or 'sandbox' for texting var $account = ''; //Account used for logging var $vat = 0; // percentage for VAT tax var $total = 0; // nothing should be needed to be changed below this line by the application using this class // countries that are in sync with other AG Projects backends var $countries=array( array("label"=>"","value"=>""), array("label"=>"Albania","value"=>"AL"), array("label"=>"Algeria","value"=>"DZ"), array("label"=>"Andorra","value"=>"AD"), array("label"=>"Angola","value"=>"AO"), array("label"=>"Anguilla","value"=>"AI"), array("label"=>"Antigua and Barbuda","value"=>"AG"), array("label"=>"Argentina","value"=>"AR"), array("label"=>"Armenia","value"=>"AM"), array("label"=>"Aruba","value"=>"AW"), array("label"=>"Australia","value"=>"AU"), array("label"=>"Austria","value"=>"AT"), array("label"=>"Azerbaijan Republic","value"=>"AZ"), array("label"=>"Bahamas","value"=>"BS"), array("label"=>"Bahrain","value"=>"BH"), array("label"=>"Barbados","value"=>"BB"), array("label"=>"Belgium","value"=>"BE"), array("label"=>"Belize","value"=>"BZ"), array("label"=>"Benin","value"=>"BJ"), array("label"=>"Bermuda","value"=>"BM"), array("label"=>"Bhutan","value"=>"BT"), array("label"=>"Bolivia","value"=>"BO"), array("label"=>"Bosnia and Herzegovina","value"=>"BA"), array("label"=>"Botswana","value"=>"BW"), array("label"=>"Brazil","value"=>"BR"), array("label"=>"British Virgin Islands","value"=>"VG"), array("label"=>"Brunei","value"=>"BN"), array("label"=>"Bulgaria","value"=>"BG"), array("label"=>"Burkina Faso","value"=>"BF"), array("label"=>"Burundi","value"=>"BI"), array("label"=>"Cambodia","value"=>"KH"), array("label"=>"Canada","value"=>"CA"), array("label"=>"Cape Verde","value"=>"CV"), array("label"=>"Cayman Islands","value"=>"KY"), array("label"=>"Chad","value"=>"TD"), array("label"=>"Chile","value"=>"CL"), array("label"=>"China Worldwide","value"=>"C2"), array("label"=>"Colombia","value"=>"CO"), array("label"=>"Comoros","value"=>"KM"), array("label"=>"Cook Islands","value"=>"CK"), array("label"=>"Costa Rica","value"=>"CR"), array("label"=>"Croatia","value"=>"HR"), array("label"=>"Cyprus","value"=>"CY"), array("label"=>"Czech Republic","value"=>"CZ"), array("label"=>"Democratic Republic of the Congo","value"=>"CD"), array("label"=>"Denmark","value"=>"DK"), array("label"=>"Djibouti","value"=>"DJ"), array("label"=>"Dominica","value"=>"DM"), array("label"=>"Dominican Republic","value"=>"DO"), array("label"=>"Ecuador","value"=>"EC"), array("label"=>"El Salvador","value"=>"SV"), array("label"=>"Eritrea","value"=>"ER"), array("label"=>"Estonia","value"=>"EE"), array("label"=>"Ethiopia","value"=>"ET"), array("label"=>"Falkland Islands","value"=>"FK"), array("label"=>"Faroe Islands","value"=>"FO"), array("label"=>"Federated States of Micronesia","value"=>"FM"), array("label"=>"Fiji","value"=>"FJ"), array("label"=>"Finland","value"=>"FI"), array("label"=>"France","value"=>"FR"), array("label"=>"French Guiana","value"=>"GF"), array("label"=>"French Polynesia","value"=>"PF"), array("label"=>"Gabon Republic","value"=>"GA"), array("label"=>"Gambia","value"=>"GM"), array("label"=>"Germany","value"=>"DE"), array("label"=>"Gibraltar","value"=>"GI"), array("label"=>"Greece","value"=>"GR"), array("label"=>"Greenland","value"=>"GL"), array("label"=>"Grenada","value"=>"GD"), array("label"=>"Guadeloupe","value"=>"GP"), array("label"=>"Guatemala","value"=>"GT"), array("label"=>"Guinea","value"=>"GN"), array("label"=>"Guinea Bissau","value"=>"GW"), array("label"=>"Guyana","value"=>"GY"), array("label"=>"Honduras","value"=>"HN"), array("label"=>"Hong Kong","value"=>"HK"), array("label"=>"Hungary","value"=>"HU"), array("label"=>"Iceland","value"=>"IS"), array("label"=>"India","value"=>"IN"), array("label"=>"Indonesia","value"=>"ID"), array("label"=>"Ireland","value"=>"IE"), array("label"=>"Israel","value"=>"IL"), array("label"=>"Italy","value"=>"IT"), array("label"=>"Jamaica","value"=>"JM"), array("label"=>"Japan","value"=>"JP"), array("label"=>"Jordan","value"=>"JO"), array("label"=>"Kazakhstan","value"=>"KZ"), array("label"=>"Kenya","value"=>"KE"), array("label"=>"Kiribati","value"=>"KI"), array("label"=>"Kuwait","value"=>"KW"), array("label"=>"Kyrgyzstan","value"=>"KG"), array("label"=>"Laos","value"=>"LA"), array("label"=>"Latvia","value"=>"LV"), array("label"=>"Lesotho","value"=>"LS"), array("label"=>"Liechtenstein","value"=>"LI"), array("label"=>"Lithuania","value"=>"LT"), array("label"=>"Luxembourg","value"=>"LU"), array("label"=>"Madagascar","value"=>"MG"), array("label"=>"Malawi","value"=>"MW"), array("label"=>"Malaysia","value"=>"MY"), array("label"=>"Maldives","value"=>"MV"), array("label"=>"Mali","value"=>"ML"), array("label"=>"Malta","value"=>"MT"), array("label"=>"Marshall Islands","value"=>"MH"), array("label"=>"Martinique","value"=>"MQ"), array("label"=>"Mauritania","value"=>"MR"), array("label"=>"Mauritius","value"=>"MU"), array("label"=>"Mayotte","value"=>"YT"), array("label"=>"Mexico","value"=>"MX"), array("label"=>"Mongolia","value"=>"MN"), array("label"=>"Montserrat","value"=>"MS"), array("label"=>"Morocco","value"=>"MA"), array("label"=>"Mozambique","value"=>"MZ"), array("label"=>"Namibia","value"=>"NA"), array("label"=>"Nauru","value"=>"NR"), array("label"=>"Nepal","value"=>"NP"), array("label"=>"Netherlands","value"=>"NL"), array("label"=>"Netherlands Antilles","value"=>"AN"), array("label"=>"New Caledonia","value"=>"NC"), array("label"=>"New Zealand","value"=>"NZ"), array("label"=>"Nicaragua","value"=>"NI"), array("label"=>"Niger","value"=>"NE"), array("label"=>"Niue","value"=>"NU"), array("label"=>"Norfolk Island","value"=>"NF"), array("label"=>"Norway","value"=>"NO"), array("label"=>"Oman","value"=>"OM"), array("label"=>"Palau","value"=>"PW"), array("label"=>"Panama","value"=>"PA"), array("label"=>"Papua New Guinea","value"=>"PG"), array("label"=>"Peru","value"=>"PE"), array("label"=>"Philippines","value"=>"PH"), array("label"=>"Pitcairn Islands","value"=>"PN"), array("label"=>"Poland","value"=>"PL"), array("label"=>"Portugal","value"=>"PT"), array("label"=>"Qatar","value"=>"QA"), array("label"=>"Republic of the Congo","value"=>"CG"), array("label"=>"Reunion","value"=>"RE"), array("label"=>"Romania","value"=>"RO"), array("label"=>"Russia","value"=>"RU"), array("label"=>"Rwanda","value"=>"RW"), array("label"=>"Saint Vincent and the Grenadines","value"=>"VC"), array("label"=>"Samoa","value"=>"WS"), array("label"=>"San Marino","value"=>"SM"), array("label"=>"S‹o TomŽ and Pr’ncipe","value"=>"ST"), array("label"=>"Saudi Arabia","value"=>"SA"), array("label"=>"Senegal","value"=>"SN"), array("label"=>"Seychelles","value"=>"SC"), array("label"=>"Sierra Leone","value"=>"SL"), array("label"=>"Singapore","value"=>"SG"), array("label"=>"Slovakia","value"=>"SK"), array("label"=>"Slovenia","value"=>"SI"), array("label"=>"Solomon Islands","value"=>"SB"), array("label"=>"Somalia","value"=>"SO"), array("label"=>"South Africa","value"=>"ZA"), array("label"=>"South Korea","value"=>"KR"), array("label"=>"Spain","value"=>"ES"), array("label"=>"Sri Lanka","value"=>"LK"), array("label"=>"St. Helena","value"=>"SH"), array("label"=>"St. Kitts and Nevis","value"=>"KN"), array("label"=>"St. Lucia","value"=>"LC"), array("label"=>"St. Pierre and Miquelon","value"=>"PM"), array("label"=>"Suriname","value"=>"SR"), array("label"=>"Svalbard and Jan Mayen Islands","value"=>"SJ"), array("label"=>"Swaziland","value"=>"SZ"), array("label"=>"Sweden","value"=>"SE"), array("label"=>"Switzerland","value"=>"CH"), array("label"=>"Taiwan","value"=>"TW"), array("label"=>"Tajikistan","value"=>"TJ"), array("label"=>"Tanzania","value"=>"TZ"), array("label"=>"Thailand","value"=>"TH"), array("label"=>"Togo","value"=>"TG"), array("label"=>"Tonga","value"=>"TO"), array("label"=>"Trinidad and Tobago","value"=>"TT"), array("label"=>"Tunisia","value"=>"TN"), array("label"=>"Turkey","value"=>"TR"), array("label"=>"Turkmenistan","value"=>"TM"), array("label"=>"Turks and Caicos Islands","value"=>"TC"), array("label"=>"Tuvalu","value"=>"TV"), array("label"=>"Uganda","value"=>"UG"), array("label"=>"Ukraine","value"=>"UA"), array("label"=>"United Arab Emirates","value"=>"AE"), array("label"=>"United Kingdom","value"=>"UK"), array("label"=>"United States","value"=>"US"), array("label"=>"Uruguay","value"=>"UY"), array("label"=>"Vanuatu","value"=>"VU"), array("label"=>"Vatican City State","value"=>"VA"), array("label"=>"Venezuela","value"=>"VE"), array("label"=>"Vietnam","value"=>"VN"), array("label"=>"Wallis and Futuna Islands","value"=>"WF"), array("label"=>"Yemen","value"=>"YE"), array("label"=>"Zambia","value"=>"ZM") ); public $pp_username; public $pricepp_pass; public $pp_signature; public $transaction_type; public $crt_path; public $sender_email; public $us_states_arr; public $can_states_arr; public $sql_host; public $sql_user; public $sql_pw; public $sql_db; public $aes_enc_pwd; public $logger; public $log_level; function CreditCardProcessor ($parameters=array()) { dprint("CreditCardProcessor()"); // process the ini configuration file $this->settings = parse_ini_file("/etc/cdrtool/paypal/cc_processor.ini"); // set the includes directory parameter set_include_path(get_include_path() . PATH_SEPARATOR . $this->settings['library_path']); // include all Paypal library files require_once 'PayPal.php'; require_once 'PayPal/Profile/Handler/Array.php'; require_once 'PayPal/Profile/API.php'; require_once 'PayPal/Profile/Handler.php'; require_once 'PayPal/Type/DoDirectPaymentRequestType.php'; require_once 'PayPal/Type/DoDirectPaymentRequestDetailsType.php'; require_once 'PayPal/Type/DoDirectPaymentResponseType.php'; require_once 'PayPal/Type/GetTransactionDetailsRequestType.php'; // Add all Paypal data types require_once 'PayPal/Type/BasicAmountType.php'; require_once 'PayPal/Type/PaymentDetailsType.php'; require_once 'PayPal/Type/AddressType.php'; require_once 'PayPal/Type/CreditCardDetailsType.php'; require_once 'PayPal/Type/PayerInfoType.php'; require_once 'PayPal/Type/PersonNameType.php'; require_once 'api_form_validators.inc.php'; require_once 'functions.inc.php'; require_once 'constants.inc.php'; // Add logger process file require_once 'cc_logger.php'; $this->logger = new cc_logger('CreditCardProcessor', PEAR_LOG_DEBUG); if ($parameters['country']) { $this->user_account['Country']=$parameters['country']; foreach ($this->countries as $_country) { if ($_country['value'] == $parameters['country']) { $this->countries_array[$_country['value']]=$_country['label']; } } } else { $this->user_account = null; foreach ($this->countries as $_country) { $this->countries_array[$_country['value']]=$_country['label']; } } $this->us_states_arr = array('AL'=>'Alabama','AK'=>'Alaska','AZ'=>'Arizona','AR'=>'Arkansas','CA'=>'California','CO'=>'Colorado','CT'=>'Connecticut','DE'=>'Delaware','DC'=>'District Of Columbia','FL'=>'Florida','GA'=>'Georgia','HI'=>'Hawaii','ID'=>'Idaho','IL'=>'Illinois', 'IN'=>'Indiana', 'IA'=>'Iowa', 'KS'=>'Kansas','KY'=>'Kentucky','LA'=>'Louisiana','ME'=>'Maine','MD'=>'Maryland', 'MA'=>'Massachusetts','MI'=>'Michigan','MN'=>'Minnesota','MS'=>'Mississippi','MO'=>'Missouri','MT'=>'Montana','NE'=>'Nebraska','NV'=>'Nevada','NH'=>'New Hampshire','NJ'=>'New Jersey','NM'=>'New Mexico','NY'=>'New York','NC'=>'North Carolina','ND'=>'North Dakota','OH'=>'Ohio','OK'=>'Oklahoma', 'OR'=>'Oregon','PA'=>'Pennsylvania','RI'=>'Rhode Island','SC'=>'South Carolina','SD'=>'South Dakota','TN'=>'Tennessee','TX'=>'Texas','UT'=>'Utah','VT'=>'Vermont','VA'=>'Virginia','WA'=>'Washington','WV'=>'West Virginia','WI'=>'Wisconsin','WY'=>'Wyoming'); $this->can_states_arr = array('AB'=>'Alberta','BC'=>'British Columbia','MB'=>'Manitoba','NB'=>'New Brunswick','NL'=>'Newfoundland/Labrador','NS'=>'Nova Scotia','NT'=>'Northwest Territories','NU'=>'Nunavut','ON'=>'Ontario','PE'=>'Prince Edward Island','QC'=>'Quebec','SK'=>'Saskatchewan','YT'=>'Yukon'); $this->sql_host = $this->settings['sql_host']; $this->sql_user = $this->settings['sql_user']; $this->sql_pw = $this->settings['sql_pw']; $this->sql_db = $this->settings['sql_db']; $this->transaction_type = $this->settings['transaction_type']; $this->sender_email = $this->settings['sender_email']; $this->aes_enc_pwd = $this->settings['aes_enc_pwd']; $this->log_path = $this->settings['logging_path']; $this->log_level = $this->settings['log_level']; $this->logger->_logDir = $this->log_path; $this->logger->_logLevel = $this->log_level; $this->logger->_log("Started session: ".session_id().""); } function setEnvironment() { // set environment variables dprint ("setEnvironment()"); if($this->environment == 'live'){ $this->pp_username = $this->settings['live_pp_username']; $this->pricepp_pass = $this->settings['live_pp_pass']; $this->pp_signature = $this->settings['live_pp_signature']; return true; } else if ($this->environment == 'sandbox') { print "

Test Paypal Enviroment

"; $this->pp_username = $this->settings['sandbox_pp_username']; $this->pricepp_pass = $this->settings['sandbox_pp_pass']; $this->pp_signature = $this->settings['sandbox_pp_signature']; return true; } else { print "Incorect Paypal Enviroment"; return false; } } function dbConnection(){ $mysql = new mysqli($this->sql_host,$this->sql_user,$this->sql_pw,$this->sql_db); return $mysql; } function getTransactionDetails ($tran_id) { // retrieves information based on transaction ID $tran_data = array(); $sql_conn = $this->dbConnection(); try { $q_result = mysqli_query($sql_conn, "CALL sproc_cc_get_transaction_details('".$tran_id."')"); while ($row = mysqli_fetch_array($q_result,MYSQLI_ASSOC)) { $tran_data = array_merge($tran_data,$row); } $q_result->close(); } catch (Exception $ex) { print $ex; } $sql_conn->close(); return $tran_data; } function getTransactionItems ($tran_id) { // retrieves list of items purchased based on transaction ID $tran_data = array(); $sql_conn = $this->dbConnection(); try { $q_result = mysqli_query($sql_conn, "CALL sproc_cc_get_transaction_items('".$tran_id."')"); $i = 0; while ($row = mysqli_fetch_array($q_result,MYSQLI_ASSOC)) { $tran_data[$i] = array_merge($tran_data,$row); $i = $i + 1; } $q_result->close(); } catch (Exception $ex) { print $ex; } $sql_conn->close(); return $tran_data; } function transaction_exists ($tran_key){ // check if the current transaction key is already in the database $ret = true; $sql_conn = $this->dbConnection(); $q_result = mysqli_query($sql_conn, "SELECT COUNT(TransactionID) AS MYCNT FROM cc_transactions WHERE TransactionKey = '".$tran_key."'"); $row = mysqli_fetch_array($q_result,MYSQLI_ASSOC); if($row['MYCNT'] == 0){ $ret = false; } $sql_conn->close(); return $ret; } function getPageURL () { $pageURL = 'http'; if ($_SERVER["HTTPS"] == "on") { $pageURL .= "s"; } $pageURL .= "://"; $pageURL .= $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"]; $this->logger->_log("Set submit action to ".$pageURL.""); return $pageURL; } function randomString($length) { $chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890'; $chars_length = (strlen($chars) - 1); $string = $chars{rand(0, $chars_length)}; for ($i = 1; $i < $length; $i = strlen($string)) { $r = $chars{rand(0, $chars_length)}; if ($r != $string{$i - 1}) $string .= $r; } return $string; } function showSubmitForm() { if (!$this->setEnvironment()) { return false; } if(count($this->cart_items) > 0) { foreach($this->cart_items as $item_array => $item_details){ $subtotal = $subtotal + $item_details['price']; } $vat_value = $this->vat/100 * $subtotal; $vat_currency = money_format('%i', $vat_value); $total = $subtotal + $vat_value; $total_currency = money_format('%i', $total); // javascript functions in header $page_head_objects = ""; $page_body_content = ""; $page_body_content.= "\n"; $page_body_content .= "\n"; $page_body_content .= ''; $page_body_content .= "
\n"; $page_body_content .= "\n"; $page_body_content .= "\n"; $page_body_content .= sprintf("\n",$this->chapter_class,_("Shopping Cart")); $page_body_content .= "\n"; // decided to display all items in the shopping cart as a list rather than a // dropdown menu /* $page_body_content .= "\n"; */ $t=0; foreach($this->cart_items as $item_array => $item_details) { $t++; $rr=floor($t/2); $mod=$t-$rr*2; if ($mod == 0) { $_class = $this->odd_row_class; } else { $_class = $this->even_row_class; } $page_body_content .= "". "". "\n"; } if ($this->vat) { if ($_class == $this->even_row_class) { $_class = $this->odd_row_class; } else { $_class = $this->even_row_class; } $page_body_content .= sprintf ("\n",$_class); $page_body_content .= sprintf("\n",_("VAT"),$this->vat,'%'); $page_body_content .= "\n"; $page_body_content .= "\n"; if ($_class == $this->even_row_class) { $_class = $this->odd_row_class; } else { $_class = $this->even_row_class; } $page_body_content .= sprintf ("\n",$_class); $page_body_content .= sprintf("\n",_("Total Due")); $page_body_content .= "\n"; $page_body_content .= "\n"; } else { if ($_class == $this->even_row_class) { $_class = $this->odd_row_class; } else { $_class = $this->even_row_class; } $page_body_content .= sprintf ("\n",$_class); $page_body_content .= sprintf("\n",_("Total Due")); $page_body_content .= "\n"; $page_body_content .= "\n"; } $page_body_content .= "\n"; $page_body_content .= "\n"; $page_body_content .= "\n"; $page_body_content .= "\n"; $page_body_content .= sprintf("\n",$this->chapter_class,_("Credit Card Details")); $page_body_content .= "\n"; $page_body_content .= sprintf ("\n",$this->even_row_class); $page_body_content .= sprintf("\n",_("Card Type")); $page_body_content .= "\n"; $page_body_content .= "\n"; $page_body_content .= sprintf ("\n",$this->odd_row_class); $page_body_content .= "\n"; $page_body_content .= "\n"; $page_body_content .= "\n"; $page_body_content .= sprintf ("\n",$this->even_row_class); $page_body_content .= sprintf("\n",_("Expiration Date")); $page_body_content .= "\n"; $page_body_content .= "\n"; $page_body_content .= sprintf ("\n",$this->odd_row_class); $page_body_content .= "\n"; $page_body_content .= "\n"; $page_body_content .= "\n"; $page_body_content .= "\n"; $page_body_content .= sprintf("\n",$this->chapter_class,_("Card Holder Information")); $page_body_content .= "\n"; $page_body_content .= sprintf ("\n",$this->even_row_class); $page_body_content .= "\n"; $page_body_content .= "\n"; $page_body_content .= "\n"; $page_body_content .= sprintf ("\n",$this->odd_row_class); $page_body_content .= "\n"; $page_body_content .= "\n"; $page_body_content .= "\n"; $page_body_content .= sprintf ("\n",$this->even_row_class); $page_body_content .= "\n"; $page_body_content .= "\n"; $page_body_content .= "\n"; $page_body_content .= sprintf ("\n",$this->odd_row_class); $page_body_content .= sprintf("\n",$this->chapter_class,_("Address")); $page_body_content .= "\n"; $page_body_content .= sprintf ("\n",$this->even_row_class); $page_body_content .= "\n"; $page_body_content .= "\n"; $page_body_content .= "\n"; /* $page_body_content .= "\n"; $page_body_content .= "\n"; $page_body_content .= "\n"; $page_body_content .= "\n"; */ $page_body_content .= sprintf ("\n",$this->odd_row_class); $page_body_content .= "\n"; $page_body_content .= "\n"; $page_body_content .= "\n"; $page_body_content .= sprintf ("\n",$this->even_row_class); $page_body_content .= "\n"; $page_body_content .= "\n"; $page_body_content .= "\n"; $page_body_content .= sprintf ("\n",$this->odd_row_class); $page_body_content .= sprintf("\n",_("State")); $page_body_content .= "\n"; $page_body_content .= "\n"; $page_body_content .= sprintf ("\n",$this->even_row_class); $page_body_content .= "\n"; $page_body_content .= "\n"; $page_body_content .= "\n"; $page_body_content .= sprintf ("\n",$this->odd_row_class); $page_body_content .= "\n"; $page_body_content .= sprintf("\n"; $page_body_content .= "\n"; $page_body_content .= "
%s
".$item_details['description']."".money_format('%i', $item_details['price'])."
%s (%s%s)
%s
%s
%s
%s\n"; $page_body_content .= "\n"; $page_body_content .= "
user_account['card_number']."\">
%s"; $page_body_content .= "\n"; $page_body_content .= "\n"; $page_body_content .= "
user_account['card_cvn']."\"
%s
user_account['FirstName']."\">
user_account['LastName']."\">
user_account['Email']."\">
%s
Sta/Aptuser_account['Address2']."\">
user_account['City']."\">
\n"; $page_body_content .= "\n"; $page_body_content .= "
%s
\n"; $page_body_content .= "
user_account['PostCode']."\">
\n",_("Purchase")); $page_body_content .= "
\n"; $page_body_content .= $this->hidden_elements; $page_body_content .= "
\n"; $page_body_close = ""; } else{ $page_body_content = ""; $page_body_start = ""; $page_body_content = _("You have no items in your cart. "); $page_body_content .= ""._("Go Back").""; $page_body_close = ""; } $arr_form_page_objects = array( 'page_head_objects' => $page_head_objects, 'page_body_start' => $page_body_start, 'page_body_content' => $page_body_content, 'page_body_close' => $page_body_close ); return $arr_form_page_objects; } function checkForm ($post_vars) { dprint("checkForm()"); // check server side things related to the submitted form $errors = array(); // check amount $amount = 0; if($post_vars['amount'] > 0){ $amount = $post_vars['amount']; }else{ $errors = array_merge($errors,array('amount'=>array('field'=>'Cart Amount','desc'=>_('Amount cannot be zero')))); } // check first name if(strlen(str_replace(" ", "", filter_var($post_vars['firstName'], FILTER_SANITIZE_STRING))) < 2 || is_string($post_vars['firstName']) == false){ $errors = array_merge($errors,array('firstname'=>array('field'=>'First Name','desc'=>_('Invalid First Name provided')))); } // check last name if(strlen(str_replace(" ", "", filter_var($post_vars['lastName'], FILTER_SANITIZE_STRING))) < 2 || is_string($post_vars['lastName']) == false){ $errors = array_merge($errors,array('lastname'=>array('field'=>'Last Name','desc'=>_('Invalid Last Name provided')))); } // check email if(strlen(str_replace(" ", "", filter_var($post_vars['emailAddress'], FILTER_SANITIZE_EMAIL))) < 6){ $errors = array_merge($errors,array('email'=>array('field'=>'Email','desc'=>_('Invalid Email Address provided')))); } // check card number if(strlen(str_replace(" ", "", filter_var($post_vars['creditCardNumber'], FILTER_SANITIZE_NUMBER_INT))) < 15 || $post_vars['creditCardNumber'] == 0){ $errors = array_merge($errors,array('ccnumber'=>array('field'=>'Card Number','desc'=>_('Invalid Credit Card Number')))); } // check expiration $time_from_exp = mktime(0, 0, 0, $post_vars['expDateMonth'], 31, $post_vars['expDateYear']); if(time() > $time_from_exp){ $errors = array_merge($errors,array('ccexp'=>array('field'=>'Card Expiration','desc'=>_('Invalid Credit Card Expiration Date')))); } // check card verify code // if(strlen($post_vars['cvv2Number']) != 3){ if(!filter_var(str_replace(" ", "", $post_vars['cvv2Number']), FILTER_VALIDATE_FLOAT) || $post_vars['cvv2Number'] < 1 || $post_vars['cvv2Number'] > 999){ $errors = array_merge($errors,array('ccvn'=>array('field'=>'Card Verification Number','desc'=>_('Invalid Card Verification Number')))); } // check address line 1 if(strlen(str_replace(" ", "", filter_var($post_vars['address1'], FILTER_SANITIZE_STRING))) < 5){ $errors = array_merge($errors,array('address1'=>array('field'=>'Address','desc'=>_('Invalid Address')))); } // check city if(strlen(str_replace(" ","",$post_vars['city'])) < 2 || !is_string($post_vars['city'])){ $errors = array_merge($errors,array('city'=>array('field'=>'City','desc'=>_('Invalid City')))); } // check country if($this->countries_array[$post_vars['country']] == ''){ $errors = array_merge($errors,array('country'=>array('field'=>'Country','desc'=>'A country must be selected'))); } // check postcode if($post_vars['zip'] == ''){ $errors = array_merge($errors,array('zip'=>array('field'=>'Postcode','desc'=>'A postal code must be provided'))); } if(count($errors) > 0){ $this->logger->_log("Errors found in form ".print_r($errors, true).""); } return $errors; } function displayProcessErrors($error=array()){ dprint("displayProcessErrors()"); $page_body_content .= "

"._("Error")."

"; $page_body_content .= "\n"; if ($error['error_code']) { $page_body_content .= sprintf("\n",$error['error_code']); } if ($error['short_message']) { $page_body_content .= sprintf("\n",$error['short_message']); } if ($error['desc']) { $page_body_content .= sprintf("\n",$error['desc']); } $page_body_content .= "
Error code:%s
Description:%s
%s
\n"; $page_body_content .= "

"._("Go Back").", "._("correct the errors and re-submit. ")."\n"; return $page_body_content; } function processPayment () { dprint("processPayment()"); if (!$this->setEnvironment()) { return false; } // return sucess and set relevant data from the transaction to variables belonging to the class $errors = array(); $pp_return = array(); $_TransactionKey = filter_var($_POST['transactionKey'], FILTER_SANITIZE_STRING); if($_TransactionKey == ''){ $pp_return = array('error'=>array('field'=>'key','desc'=>_('Missing transaction key'))); } else if (CreditCardProcessor::transaction_exists($_TransactionKey) == true){ $pp_return = array('error'=>array('field'=>'reload','desc'=>_('Transaction already exists. Do not press the browser reload button.'))); } else { $pid = ProfileHandler::generateID(); $handler = & ProfileHandler_Array::getInstance(array( 'username' => $this->pp_username, 'certificateFile' => null, 'subject' => null, 'environment' => $this->environment ) ); $profile = new APIProfile($pid, $handler); $profile->setAPIUsername($this->pp_username); $profile->setAPIPassword($this->pricepp_pass); $profile->setSignature($this->pp_signature); $profile->setCertificateFile(null); $profile->setEnvironment($this->environment); $dp_request =& PayPal::getType('DoDirectPaymentRequestType'); $paymentType = $this->transaction_type; $firstName = filter_var($_POST['firstName'], FILTER_SANITIZE_STRING); $lastName = filter_var($_POST['lastName'], FILTER_SANITIZE_STRING); $emailAddress = filter_var($_POST['emailAddress'], FILTER_SANITIZE_EMAIL); $creditCardType = filter_var($_POST['creditCardType'], FILTER_SANITIZE_STRING); $creditCardNumber = filter_var($_POST['creditCardNumber'], FILTER_SANITIZE_NUMBER_INT); $expDateMonth = filter_var($_POST['expDateMonth'], FILTER_SANITIZE_NUMBER_INT); // Month must be padded with leading zero $padDateMonth = str_pad($expDateMonth, 2, '0', STR_PAD_LEFT); $expDateYear = filter_var($_POST['expDateYear'], FILTER_SANITIZE_NUMBER_INT); $cvv2Number = filter_var($_POST['cvv2Number'], FILTER_SANITIZE_STRING); $address1 = filter_var($_POST['address1'], FILTER_SANITIZE_STRING); $address2 = filter_var($_POST['address2'], FILTER_SANITIZE_STRING); $city = filter_var($_POST['city'], FILTER_SANITIZE_STRING); $state = filter_var($_POST['state'], FILTER_SANITIZE_STRING); $zip = filter_var($_POST['zip'], FILTER_SANITIZE_STRING); $country = filter_var($_POST['country'], FILTER_SANITIZE_STRING); $this->total = $_POST['amount']; // Populate SOAP request information // Payment details $OrderTotal =& PayPal::getType('BasicAmountType'); $OrderTotal->setattr('currencyID', 'USD'); $OrderTotal->setval($this->total, 'iso-8859-1'); $PaymentDetails =& PayPal::getType('PaymentDetailsType'); $PaymentDetails->setOrderTotal($OrderTotal); $shipTo =& PayPal::getType('AddressType'); $shipTo->setName($firstName.' '.$lastName); $shipTo->setStreet1($address1); $shipTo->setStreet2($address2); $shipTo->setCityName($city); $shipTo->setStateOrProvince($state); $shipTo->setCountry($country); $shipTo->setPostalCode($zip); $PaymentDetails->setShipToAddress($shipTo); $dp_details =& PayPal::getType('DoDirectPaymentRequestDetailsType'); $dp_details->setPaymentDetails($PaymentDetails); // Credit Card info $card_details =& PayPal::getType('CreditCardDetailsType'); $card_details->setCreditCardType($creditCardType); $card_details->setCreditCardNumber($creditCardNumber); $card_details->setExpMonth($padDateMonth); $card_details->setExpYear($expDateYear); $card_details->setCVV2($cvv2Number); $payer =& PayPal::getType('PayerInfoType'); $person_name =& PayPal::getType('PersonNameType'); $person_name->setFirstName($firstName); $person_name->setLastName($lastName); $payer->setPayerName($person_name); $payer->setPayerCountry($country); $payer->setAddress($shipTo); $card_details->setCardOwner($payer); $dp_details->setCreditCard($card_details); $dp_details->setIPAddress($_SERVER['SERVER_ADDR']); // set our session ID to be sent with PayPal Request if ($this->note) { $_id=$this->note.' '.$_TransactionKey; } else { $_id=$_TransactionKey; } $dp_details->setMerchantSessionId($_id); //$dp_details->setMerchantSessionId($_TransactionKey); $dp_details->setPaymentAction($paymentType); $dp_request->setDoDirectPaymentRequestDetails($dp_details); $caller =& PayPal::getCallerServices($profile); $this->logger->_log("CC Profile: ".print_r($profile, true).""); $this->logger->_log("Request Details: ".print_r($dp_details, true).""); // Execute SOAP request $response = $caller->DoDirectPayment($dp_request); $this->logger->_log("Response Details: ".print_r($response, true).""); if (!method_exists($response,'getAck')) { $error = 'Response is a '.get_class($response).' object:'; if(method_exists($response,'getMessage')){ $_log.="\n\xA0\xA0getMessage() => ".strval($response->getMessage()); } /* foreach(get_object_vars($response) as $k=>$v){ $_log.="\n\xA0\xA0$k => ".strval($v); } */ // Finish handling the error, etc. For example, $pp_return = array('error'=>array('field'=>'Card Processing','desc'=>'Unknown Processing Error')); $log=sprintf("Error: SIP Account %s - CC transaction failed to process: %s",$this->account,$_log); syslog(LOG_NOTICE, $log); } else { $ack = $response->getAck(); if ($ack == "Success") { $pp_return = array('success'=>array('field'=>'Card Processing', 'desc'=>$response) ); } else { $pp_return = array('error'=>array('field' => 'Card Processing', 'desc' => $response->Errors->LongMessage, 'short_message' => $response->Errors->ShortMessage, 'error_code' => $response->Errors->ErrorCode, 'correlation_id' => $response->CorrelationID ) ); $log=sprintf("Error: %s (%s) %s, correlation id %s", $response->Errors->ShortMessage, $response->Errors->ErrorCode, $response->Errors->LongMessage, $response->CorrelationID ); $this->logger->_log($log); } } } return $pp_return; } function saveOrder ($form_data, $payment_results, $extra_information=array()) { dprint("saveOrder()"); // save order information in a database, etc if ($payment_results['success']) { $_TransactionNum = $payment_results['success']['desc']->TransactionID; $amt_obj = $payment_results['success']['desc']->getAmount(); $amt = $amt_obj->_value; $currency_cd = $amt_obj->_attributeValues['currencyID']; $_TotalAmount = $amt; $_Currency = $currency_cd; $_AVSCode = $payment_results['success']['desc']->AVSCode; $_CVV2Code = $payment_results['success']['desc']->CVV2Code; $_PendingReason = $payment_results['success']['desc']->PendingReason; $_PaymentStatus = $payment_results['success']['desc']->PaymentStatus; $_FMFDetails = $payment_results['success']['desc']->FMFDetails; $_ThreeDSecureResponse = $payment_results['success']['desc']->ThreeDSecureResponse; $_APITimestamp = $payment_results['success']['desc']->Timestamp; $_AckResponse = $payment_results['success']['desc']->Ack; $_CorrelationID = $payment_results['success']['desc']->CorrelationID; $_Errors = $payment_results['success']['desc']->Errors; } else { $_TransactionNum = ''; $amt_obj = ''; $amt = ''; $currency_cd = ''; $_TotalAmount = ''; $_Currency = ''; $_AVSCode = ''; $_CVV2Code = ''; $_PendingReason = ''; $_PaymentStatus = ''; $_FMFDetails = ''; $_ThreeDSecureResponse = ''; $_APITimestamp = ''; $_AckResponse = ''; $_CorrelationID = ''; $_Errors = ''; } $_TransactionKey = filter_var($form_data['transactionKey'], FILTER_SANITIZE_STRING); $_AES_ENC_PWD = $this->aes_enc_pwd; $_FirstName = filter_var($form_data['firstName'], FILTER_SANITIZE_STRING); $_LastName = filter_var($form_data['lastName'], FILTER_SANITIZE_STRING); $_UserAcct = $_SESSION['login']; // change this with actual account ientifier session $_Email = filter_var($form_data['emailAddress'], FILTER_SANITIZE_EMAIL);; $_CCType = filter_var($form_data['creditCardType'], FILTER_SANITIZE_STRING); $_CCNum = filter_var($form_data['creditCardNumber'], FILTER_SANITIZE_NUMBER_INT); $_CCLast = substr($_CCNum,-4); $_CCVCode = filter_var($form_data['cvv2Number'], FILTER_SANITIZE_STRING); $_CCExpMonth = filter_var($form_data['expDateMonth'], FILTER_SANITIZE_NUMBER_INT); $_CCExpYear = filter_var($form_data['expDateYear'], FILTER_SANITIZE_NUMBER_INT); $_BillingAddress1 = filter_var($form_data['address1'], FILTER_SANITIZE_STRING); $_BillingAddress2 = filter_var($form_data['address2'], FILTER_SANITIZE_STRING); $_BillingCity = filter_var($form_data['city'], FILTER_SANITIZE_STRING); $_BillingState = filter_var($form_data['state'], FILTER_SANITIZE_STRING); $_BillingPostalCode = filter_var($form_data['zip'], FILTER_SANITIZE_STRING); $_BillingCountry = filter_var($form_data['country'], FILTER_SANITIZE_STRING); $_RequesterIP = $_SERVER['REMOTE_ADDR']; $_RequesterSID = session_id(); // save billing name and address for later use $this->billing_name = $_FirstName.' '.$_LastName; $this->billing_address = $_BillingAddress1."\n"; if ($_BillingAddress2) { $this->billing_address .= $_BillingAddress2."\n"; } $this->billing_address .= $_BillingPostalCode.', '.$_BillingCity."\n"; if ($_BillingState) { $this->billing_address .= $_BillingState.', '.$_BillingCountry; } else { $this->billing_address .= $_BillingCountry; } $sql_conn = $this->dbConnection(); // insert transaction information try{ mysqli_query($sql_conn, "CALL sproc_cc_add_transaction( '".$_TransactionKey."', '".$_TransactionNum."', '".$this->environment."', '".$_TotalAmount."', '".$_Currency."', '".$_AVSCode."', '".$_CVV2Code."', '".$_PendingReason."', '".$_PaymentStatus."', '".$_FMFDetails."', '".$_ThreeDSecureResponse."', '".$_APITimestamp."', '".$_AckResponse."', '".$_CorrelationID."', '".$_Errors."', '".$_AES_ENC_PWD."', '".$_FirstName."', '".$_LastName."', '".$_UserAcct."', '".$_Email."', '".$_CCType."', '".$_CCNum."', '".$_CCLast."', '".$_CCVCode."', '".$_CCExpMonth."', '".$_CCExpYear."', '".$_BillingAddress1."', '".$_BillingAddress2."', '".$_BillingCity."', '".$_BillingState."', '".$_BillingPostalCode."', '".$_BillingCountry."', '".$_RequesterIP."', '".$_RequesterSID."' )"); } catch (Exception $ex) { //print $ex; syslog(LOG_ERR,"CC_transaction [".date("Y-m-d H:i:s")."]: ".$ex.""); } // insert item purchase information foreach ($form_data['cart_item'] as $cart_item_key => $service_id){ try{ mysqli_query($sql_conn, "CALL sproc_cc_add_purchase_items( '".$_TransactionNum."', '".$service_id."', '".$form_data['cart_item_price'][$cart_item_key]."', '".$_Currency."' )"); } catch (Exception $ex) { //print $ex; syslog(LOG_ERR,"CC_transaction [".date("Y-m-d H:i:s")."]: ".$ex.""); } } $sql_conn->close(); $this->transaction_data = $this->getTransactionDetails($_TransactionNum); $this->notifyMerchant($extra_information); return $_TransactionNum; } function deliverMerchandise ($transaction_data) { dprint ("deliverMerchandise()"); //dprint_r($transaction_data); // use this information as needed // information is in the following format: /* array(14) { ["TRANSACTION_ID"]=> string(17) "6J581384EM0001112" ["TOTAL_AMOUNT"]=> string(5) "30.00" ["CURRENCY"]=> string(3) "USD" ["PURCHASE_TIMESTAMP"]=> string(19) "2009-11-11 21:50:40" ["FIRST_NAME"]=> string(6) "Andrew" ["LAST_NAME"]=> string(7) "Madison" ["AG_USER_ACCOUNT"]=> string(0) "" ["USER_EMAIL"]=> string(18) "uskratos@gmail.com" ["ADDRESS1"]=> string(21) "3619 E. Long Lake Rd." ["ADDRESS2"]=> string(0) "" ["CITY"]=> string(7) "Phoenix" ["STATE"]=> string(2) "AZ" ["POSTCODE"]=> string(5) "85048" ["COUNTRY"]=> string(2) "US" } */ } function notifyBuyer () { dprint ("notifyBuyer()"); if (!$this->notify_buyer) return true; if (!is_array($this->transaction_data)) return false; // send email notifications to te customer etc... $items_purchase_list = $this->getTransactionItems($this->transaction_data['TRANSACTION_ID']); $msg = "Dear ".$this->transaction_data['FIRST_NAME']." ".$this->transaction_data['LAST_NAME'].",\n\n"; $msg .= "This message is to confirm that on ".$this->transaction_data['PURCHASE_TIMESTAMP']." "; $msg .= "you purchased from AG Projects services in amount of ".$this->total." ".$this->transaction_data['CURRENCY'].".\n\n"; $msg .= "\n"; $msg .= "Your account is credited and you can use your available credit immediately. If you "; $msg .= "do not recognize this charge, please contact us at ".$this->sender_email." with Transaction ID ".$this->transaction_data['TRANSACTION_ID']." as reference.\n\n"; $msg .= "Thank you for your purchase!\n\n"; $msg .= "AG Projects"; return $this->sendEmail($this->sender_email,$this->transaction_data['USER_EMAIL'],'AG Projects Purchase Notice',$msg); } function notifyMerchant ($extra_information=array()) { dprint ("notifyMerchant()"); if (!$this->notify_merchant) return true; if (!is_array($this->transaction_data)) return false; // send email notifications to AG Projects $items_purchase_list = $this->getTransactionItems($this->transaction_data['TRANSACTION_ID']); $msg = "New Credit Card Transaction:\n"; $msg .= "Transaction Number: ".$this->transaction_data['TRANSACTION_ID']."\n"; $msg .= "Amount: ".$this->total." ".$this->transaction_data['CURRENCY']."\n\n"; $msg .= "Items Purchased:\n\n"; foreach($items_purchase_list as $item_purchase){ $msg .= "Item: ".$item_purchase['ITEM_NAME']." Price: ".$item_purchase['AMOUNT']." ".$item_purchase['CURRENCY']."\n"; } $msg .= "\n"; $msg .= "Purchased On: ".$this->transaction_data['PURCHASE_TIMESTAMP']."\n"; $msg .= "First Name: ".$this->transaction_data['FIRST_NAME']."\n"; $msg .= "Last Name: ".$this->transaction_data['LAST_NAME']."\n"; $msg .= "User Account: ".$this->transaction_data['AG_USER_ACCOUNT']."\n"; $msg .= "Email: ".$this->transaction_data['USER_EMAIL']."\n"; $msg .= "Address: ".$this->transaction_data['ADDRESS1']." ".$this->transaction_data['ADDRESS2']."\n"; $msg .= "City: ".$this->transaction_data['CITY']."\n"; $msg .= "State: ".$this->transaction_data['STATE']."\n"; $msg .= "Postcode: ".$this->transaction_data['POSTCODE']."\n"; $msg .= "Country: ".$this->transaction_data['COUNTRY']."\n"; $msg .= "User IP: ".$_SERVER['REMOTE_ADDR']."\n"; $msg .= "\n"; foreach (array_keys($extra_information) as $idx) { $msg .= sprintf("%s: %s\n",$idx,$extra_information[$idx]); } return $this->sendEmail($this->sender_email,$this->sender_email,'Credit Card Purchase Notification',$msg); } function sendEmail ($from, $to, $subject, $msg) { dprint ("sendEmail()"); // send email notifications $extra = "From: ".$from."" . "\r\n" . "Reply-To: ".$from."" . "\r\n" . "X-Mailer: PHP/" . phpversion(); $mail_subject = $subject; $mail_body = $msg; if (mail($to, $mail_subject, $mail_body, $extra)) { return true; } else { return false; } } + + function refundPayment ($transaction_id, $type='Full', $amount='', $note='') { + if (!$this->setEnvironment()) { + return false; + } + + if (!$transaction_id) { + return false; + } + + if (!$note) { + $note=sprintf('Refund %s', $transaction_id); + } + + $pid = ProfileHandler::generateID(); + $handler = & ProfileHandler_Array::getInstance(array( + 'username' => $this->pp_username, + 'certificateFile' => null, + 'subject' => null, + 'environment' => $this->environment + ) + ); + + $profile = new APIProfile($pid, $handler); + $profile->setAPIUsername($this->pp_username); + $profile->setAPIPassword($this->pricepp_pass); + $profile->setSignature($this->pp_signature); + $profile->setCertificateFile(null); + $profile->setEnvironment($this->environment); + + $ref_details =& PayPal::getType('RefundTransactionRequestType'); + $ref_details->setVersion("51.0"); + + $transactionID = filter_var($transaction_id, FILTER_SANITIZE_STRING); + $refundType = filter_var($type, FILTER_SANITIZE_STRING); + $refundAmount = filter_var($amount, FILTER_SANITIZE_STRING); + $refundNote = filter_var($note, FILTER_SANITIZE_STRING); + + $ref_details->setTransactionID($transactionID, 'iso-8859-1'); + $ref_details->setRefundType($refundType, 'iso-8859-1'); + $ref_details->setAmount($refundAmount, 'iso-8859-1'); + $ref_details->setMemo($refundNote, 'iso-8859-1'); + + $caller =& PayPal::getCallerServices($profile); + $this->logger->_log("Refund Profile: ".print_r($profile, true).""); + $this->logger->_log("Refund Request Details: ".print_r($ref_details, true).""); + + $response = $caller->RefundTransaction($ref_details); + $this->logger->_log("Refund Response Details: ".print_r($response, true).""); + + $ack = $response->getAck(); + + $ref_return = array(); + + if ($ack == 'Success') { + $ref_return = array('success'=>array('field' => 'Refund Processing', + 'desc' => $response + ) + ); + } else { + $ref_return = array('error'=>array('field' => 'Refund Processing', + 'desc' => $response->Errors->LongMessage, + 'short_message' => $response->Errors->ShortMessage, + 'error_code' => $response->Errors->ErrorCode, + 'correlation_id' => $response->CorrelationID + ) + ); + } + + return $ref_return; + } } ?>